package com.casstime.demo;

import lombok.Data;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.io.RandomAccessFile;
import java.text.SimpleDateFormat;
import java.util.*;

@Data
public class CodeStyleDemo extends Thread{

    private Boolean isSuccess;
    private Boolean delete;

    public static final Long MAX_STOCK_COUNTte = 50000L;

    public void codeStyleTest(){
        Map<String, String> map = new HashMap<String, String>();
    }


    public int method() {
        Integer a = null;
        return a;
    }

    public void initHashMap(){
        Map<String, String> map = new HashMap<String, String>();
    }

    public void complexLogic(){
        Integer a = 0,b = 0,c = 0;

        if ((a != null) && (b != null) || (c != null)) {
        }
    }

    public void negetiveCondition(){
        Integer a = null;
        if (!(a >= 628)) {
            // ...
        }
    }

    public void formatDateTime(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }

    public void getRandomKey(){
        Long randomLong =(long) (Math.random() * 10);
    }

    public void methodDemo() {

        int a = 3;// Put single line comment above code. (Note: align '//' comment with code)

    }


    public void stringJoin() {
        List<String> tagNameList = new ArrayList<>();
        String result = "";
        for (String string : tagNameList) {
            result = result + string;
        }
    }

    public void opreateSubList() {
        List<String> originList = new ArrayList<String>();
        originList.add("22");
        List<String> subList = originList.subList(0, 1);
        //warn
        originList.add("22");
    }

    public void CollectionToArray(){
        List<String> c = new ArrayList<>();

        Integer[] a = (Integer [])c.toArray();
    }

    public void modifyArray(){
        List<String> t   = Arrays.asList("a","b","c");
        //warn
        t.add("22");
        //warn
        t.remove("22");
        //warn
        t.clear();
    }

    @Transactional(rollbackFor = Exception.class)
    public void transaction() {
        //some code
        //db operation
    }

    public void opreateArrayInLoop(){
        List<String> originList = new ArrayList<String>();
        originList.add("22");
        for (String item : originList) {
            //warn
            originList.add("bb");
        }
    }

    public void magicValue(){
        String key = "";
        if (key.equals("Id#taobao_1")) {
            //...
        }
    }

    public long returnInfinal(){
        try {
            File file = new File("");
            RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
            return randomAccessFile.length();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            return 0L;
        }
    }

    public void subListToList() {
        List<String> list = new ArrayList<String>();
        list.add("22");
        //warn
        List<String> test = (ArrayList<String>) list.subList(0, 1);
    }

    public void initLong(){
        //It is hard to tell whether it is number 11 or Long 1.
        Long warn = 1l;
    }
















}
